/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 * 
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
 * 
 * Use is subject to license terms.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
 * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * 
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ************************************************************************/

using System;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Linq;

namespace AODL.Document.TextDocuments
{
    /// <summary>
    /// DocumentManifest global Document Manifest
    /// </summary>
    public class DocumentManifest
    {
        /// <summary>
        /// The file name
        /// </summary>
        public static readonly string FileName = "manifest.xml";

        /// <summary>
        /// The folder name
        /// </summary>
        public static readonly string FolderName = "META-INF";

        /// <summary>
        /// Gets or sets the styles.
        /// </summary>
        /// <value>The styles.</value>
        public XDocument Manifest { get; set; }

        /// <summary>
        /// Load the style from assmebly resource.
        /// </summary>
        public virtual void New()
        {
            Assembly ass = Assembly.GetExecutingAssembly();
            Stream str = ass.GetManifestResourceStream("AODL.Resources.OD.manifest.xml");
            using (XmlReader reader = XmlReader.Create(str))
            {
                Manifest = XDocument.Load(reader);
            }
        }

        public void LoadFromFile(Stream file)
        {
            string contents;
            using (TextReader reader = new StreamReader(file))
            {
                contents = reader.ReadToEnd();
            }
            try
            {
                Manifest = XDocument.Parse(contents);
            }
            catch (Exception)
            {
                contents = contents.Replace(
                    "<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">",
                    "");
                Manifest = XDocument.Parse(contents);
            }
        }
    }
}

/*
 * $Log: DocumentManifest.cs,v $
 * Revision 1.2  2008/04/29 15:39:56  mt
 * new copyright header
 *
 * Revision 1.1  2007/02/25 08:58:58  larsbehr
 * initial checkin, import from Sourceforge.net to OpenOffice.org
 *
 * Revision 1.1  2006/01/29 11:28:30  larsbm
 * - Changes for the new version. 1.2. see next changelog for details
 *
 * Revision 1.3  2005/12/12 19:39:17  larsbm
 * - Added Paragraph Header
 * - Added Table Row Header
 * - Fixed some bugs
 * - better whitespace handling
 * - Implmemenation of HTML Exporter
 *
 * Revision 1.2  2005/11/20 17:31:20  larsbm
 * - added suport for XLinks, TabStopStyles
 * - First experimental of loading dcuments
 * - load and save via importer and exporter interfaces
 *
 * Revision 1.1  2005/11/06 14:55:25  larsbm
 * - Interfaces for Import and Export
 * - First implementation of IExport OpenDocumentTextExporter
 *
 */